<template>
  <!-- <div id="echartsView" class="className"/> -->
  <div>
    <div id="teacheredu" style="width:100%; height:500px"></div>
  </div>
</template>

<script>
import echarts from 'echarts'

export default {
  props: {
    specialtyNum: {
      type: Number,
      default() {
        return 0
      }
    },
    undergraduateNum: {
      type: Number,
      default() {
        return 0
      }
    },
    masterNum: {
      type: Number,
      default() {
        return 0
      }
    },
    doctorNum: {
      type: Number,
      default() {
        return 0
      }
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initChart()
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(document.getElementById('teacheredu'))
      this.chart.setOption({
        title: {
          text: '教师学历分析',
          x: 'left'
        },
        tooltip: {
          trigger: 'item',
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
          orient: 'vertical',
          x: 'right'
        },
        series: [
          {
            name: '教师人数',
            type: 'pie',
            selectedMode: 'single',
            radius: '55%',
            center: ['50%', '60%'],
            data: [
              {
                value: this.specialtyNum,
                name: '专科',
                itemStyle: {
                  color: '#c23531'
                }
              },
              {
                value: this.undergraduateNum,
                name: '本科',
                itemStyle: {
                  color: '#1E90FF'
                },
                selected: true
              },
              {
                value: this.masterNum,
                name: '硕士',
                itemStyle: {
                  color: '#FF69B4'
                },
              },
              {
                value: this.doctorNum,
                name: '博士',
                itemStyle: {
                  color: '#FFD700'
                }
              }
            ]
          }
        ]
      })
    }
  }
}
</script>
